<?php

namespace backend\controllers;

use yii;
use backend\models\Basepic;
use backend\models\Basemodule;

class NetController extends CommonController
{
    public function actionIndex()
    {
        $moduleId = yii::$app->request->get('moduleId');
        $module = Basemodule::findOne(['Id' => $moduleId]);
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $pageCurrent = $post['pageCurrent'];
            $pageSize = $post['pageSize'];
            $message = new Basepic();
            $data = $message->getPicData($post, $pageCurrent, $pageSize);
            return $this->renderJson($data);
        }
        $cItem = Basemodule::getMoreRole($this->roleId, $moduleId);
        $data = [
            'module' => $module,
            'cItem' => $cItem
        ];
        return $this->renderPartial('index',$data);
    }

    public function actionCreate()
    {
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            if (empty($post['id'])){//添加
                $master = new Basepic();
                $result = $master->insertData($post);
            }else{//修改
                $master = Basepic::findOne($post['id']);
                $result = $master->updateData($post);
            }
            return $this->renderJson($result);
        }else{
            $id = yii::$app->request->get('id');
            $pic = Basepic::findOne($id);
            $data = [
                'pic' => $pic,
            ];
            return $this->renderPartial('create', $data);
        }
    }

    public function actionHandler()
    {
        if (yii::$app->request->isPost){
            $post = yii::$app->request->post();
            $pic = new Basepic();
            $result = $pic->deleteData($post);
            return $this->renderJson($result);
        }
    }

}
